clear;

addpath(genpath('[path for spatial econometrics package]'))
addpath(genpath('[a path]\REStat replication\matlab programs\'))
% start time counting
tic

% load the data
data = csvread('[a path]\REStat replication\matlab programs\mdata.txt',1);
Wlag = csvread('[a path]\REStat replication\Matlab programs\W.txt',1);
% 1st column of x should contain constant

x=[ones(rows(data),1) data(:,2:cols(data))];
y=data(:,1);

prior.lflag = 1;
ndraw = 1100; nomit = 100;
prior.rval = 4; %choose 4 if expect a lot of heteroskedasticity, 30 for none; 
W=Wlag;
% LeSage estimates
res1 = sarp_g(y,x,W,ndraw,nomit,prior);
prt(res1); % print the output


yhat= res1.yhat;
csvwrite('[a path]\REStat replication\Matlab programs\yhatar.txt',yhat);
    
% elapsed time
toc











